/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.game.map;

/**
 *
 * @author pson
 */
public class MapGenerator {
    
    public void generateMap(MapController mc, int width, int height) {
        Map m = new Map();
        m.clearMap(width, height);
        
        int num = (width * height * 70) / 100;
        
        int x = width / 2;
        int y = height / 2;
        
        int i = 0;
        Tile init = new Tile(x, y);
        mc.addTile(init);
        while (i < num) {
            //create a random tile next to an existing tile
            Tile t = mc.createRandomNeighbour(x, y);
            //If the tile was not created, it will return null
            if (t != null) {
                //Add the new tile to the list
                mc.addTile(t);
                //iterate only if a new tile was created
                ++i;
            }
            //Grab a random existing tile to create the new neighboured tile
            Tile nt = mc.getRandomTile();
            x = nt.getX();
            y = nt.getY();
        }
        
        mc.setMap(m);
    }
}
